<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org"
	xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>车保汇收银台</title>
<meta charset="utf-8"></meta>
</head>
<script type="text/javascript" th:inline="javascript">
	var code=[[${code}]];
	var state=[[${state}]];
	var successUrl="";
	var errorUrl="";
	
	/**微信内置支付对象*/
	function onBridgeReady(){
		var appId=[[${appId}]];
		var timeStamp=[[${timeStamp}]];
		var nonceStr=[[${nonceStr}]];
		var pkg=[[${pkg}]];
		var signType=[[${signType}]];
		var paySign=[[${paySign}]];
		
		WeixinJSBridge.invoke(
		     'getBrandWCPayRequest', {
		      	"appId": appId,     //公众号名称，由商户传入     
		         "timeStamp": timeStamp,         //时间戳，自1970年以来的秒数     
		         "nonceStr": nonceStr, //随机串     
		         "package": pkg,     
		         "signType": signType,         //微信签名方式：     
		         "paySign": paySign //微信签名 
		       },
		       function(res){
		    	   if(res.err_msg == "get_brand_wcpay_request:ok" ) { // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
		    		   	errHtml(successUrl);
			        }else{
			        	errHtml(errorUrl);
			        }  
		       }
		   ); 
	}
	
	/**判断事实微信浏览器*/
	function wxPrice(){
		if (typeof WeixinJSBridge == "undefined"){
			if( document.addEventListener ){
				document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
			 }else if (document.attachEvent){
			 	document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
			 	document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
			  }
		}else{
			   onBridgeReady();
		}
	}
	
	/**页面跳转**/
	function errHtml(url){
		location.href=url;
	}
	
	/**收银台*/
	function shouyintai(){
		if(code){
			successUrl=[[${successUrl}]];
			errorUrl=[[${errorUrl}]];
			if(state){
				wxPrice();
			}else{
				errHtml(errorUrl);
			}
		}else{
			var errmsg=[[${msg}]];
			var url=[[${url}]];
			if(typeof url == "undefined"){
				window.onload=function(){
					 document.getElementById("errId").style.display="block";
					 document.getElementById("errMsg").innerText=errmsg;
				}
			}else{
				location.href=url;
			}
		}
	}
	
	/**自动运行*/
	shouyintai();
</script>
<body>
	<div id="errId" style="display: none;">
		<br />
		<br />
		<h1 id="errMsg" style="text-align: center;">服务器错误!!!</h1>
	</div>
</body>
</html>